#include "BlowingWidget.h"
#include <QPainter>
#include <QDebug>

BlowingItem::BlowingItem(const QString &title, const QString &value, QWidget *parent)
    : QFrame(parent)
    , m_title(title)
    , m_value(value)
{
    setupUI();
}

BlowingItem::~BlowingItem()
{
}

void BlowingItem::setupUI()
{
    QVBoxLayout *vLayout = new QVBoxLayout(this);
    vLayout->setContentsMargins(0, 0, 0, 0);
    vLayout->setSpacing(0);

    QLabel *titleLabel = new QLabel(m_title);
    titleLabel->setStyleSheet("color: #CCFFFF; font-size: 16px; font-weight: medium; border: none;");
    titleLabel->setAlignment(Qt::AlignCenter);
    vLayout->addWidget(titleLabel);

    m_valueLabel = new QLabel(m_value);
    m_valueLabel->setStyleSheet("color: #2FFAFD; font-size: 20px; font-weight: bold; border-image: url(:/img/images/Label01.png);");
    m_valueLabel->setAlignment(Qt::AlignCenter);
    vLayout->addWidget(m_valueLabel);

    QLabel *lineLabel = new QLabel();
    lineLabel->setStyleSheet("border-image: url(:/img/images/Divider line.png);");
    vLayout->addWidget(lineLabel);
}

void BlowingItem::setValue(const QString &value)
{
    m_value = value;
    if (m_valueLabel) {
        m_valueLabel->setText(m_value);
    }
}

QString BlowingItem::getValue() const
{
    return m_value;
}

BlowingWidget::BlowingWidget(const QString &title, QWidget *parent)
    : CommonContainer(title, false, 2, parent)
{
    setupUI();
    setupConnections();
}

BlowingWidget::~BlowingWidget()
{
}

void BlowingWidget::setupUI()
{
    m_contentLayout = new QVBoxLayout();
    m_contentLayout->setContentsMargins(10, 10, 10, 10);
    m_contentLayout->setSpacing(0);
    
    m_currentTimeItem = new BlowingItem("当前吹炼时间", "5'31\"");
    
    m_remainingTimeItem = new BlowingItem("预计剩余吹炼时长", "16'10\"");
    
    m_temperatureItem = new BlowingItem("当前温度", "");
    
    m_carbonContentItem = new BlowingItem("当前碳含量", "");
    
    m_operatingModeItem = new BlowingItem("操作模式", "单渣");
    
    m_contentLayout->addWidget(m_currentTimeItem);
    m_contentLayout->addWidget(m_remainingTimeItem);
    m_contentLayout->addWidget(m_temperatureItem);
    m_contentLayout->addWidget(m_carbonContentItem);
    m_contentLayout->addWidget(m_operatingModeItem);
    
    QWidget *contentWidget = new QWidget();
    contentWidget->setLayout(m_contentLayout);

    setContentWidget(contentWidget);
}

void BlowingWidget::setupConnections()
{
}

void BlowingWidget::setCurrentBlowingTime(const QString &time)
{
    if (m_currentTimeItem) {
        m_currentTimeItem->setValue(time);
    }
}

void BlowingWidget::setEstimatedRemainingTime(const QString &time)
{
    if (m_remainingTimeItem) {
        m_remainingTimeItem->setValue(time);
    }
}

void BlowingWidget::setCurrentTemperature(const QString &temperature)
{
    if (m_temperatureItem) {
        m_temperatureItem->setValue(temperature);
    }
}

void BlowingWidget::setCurrentCarbonContent(const QString &content)
{
    if (m_carbonContentItem) {
        m_carbonContentItem->setValue(content);
    }
}

void BlowingWidget::setOperatingMode(const QString &mode)
{
    if (m_operatingModeItem) {
        m_operatingModeItem->setValue(mode);
    }
}
